package com.wxy.demo.controller;

import com.wxy.demo.util.IpUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Iterator;

/**
 * <p>
 * ip地址测试
 * </p>
 *
 * @author e-Xiaoyuan.Wang
 * @since 2022/11/10 16:18
 */
@RestController
@RequestMapping("/ip")
public class IpController {

    @GetMapping("/test")
    public String test(HttpServletRequest request) {
        Iterator<String> names = request.getHeaderNames().asIterator();
        while (names.hasNext()) {
            System.out.println(names.next());
        }
        System.out.println("--------------");
        return "success:" + IpUtils.getIp(request);
    }
}
